package com.lagou.subjectfive;

import org.w3c.dom.ls.LSOutput;

import java.security.PublicKey;
import java.util.*;

/**
 * 扑克类
 */
public class Poker {
    /**
     * 底牌数量
     */
    public static final int HOLE_CARDS = 3;
    /**
     * 牌堆总数量
     */
    public static final int TOTAL_CARDS = 54;
    /**
     * 54张卡片
     */
    List<PokerCard> cards = new ArrayList<>();
    /**
     * 游戏中的卡牌组
     */
    List<PokerCard> GameCards = Arrays.asList(new PokerCard[TOTAL_CARDS]);

    /**
     * 三位玩家以及底牌存放
     */
    List<PokerCard> PlayerOne = new ArrayList<>();
    List<PokerCard> PlayerTwo = new ArrayList<>();
    List<PokerCard> PlayerThree = new ArrayList<>();
    List<PokerCard> Hole = new ArrayList<>();

    /**
     * 卡片种类
     */
    String[] cardTypes = {"大王", "小王", "2", "A", "K", "Q", "J", "10", "9", "8", "7", "6", "5", "4", "3"};

    //初始化扑克牌
    public Poker() {
        int count = 0;
        for (String card : cardTypes) {
            if (card == "大王" || card == "小王") {
                //大小王没有花色
                cards.add(new PokerCard(++count, card, CardColorEnum.None));
            } else {
                //四种花色 黑桃红星梅花方块
                cards.add(new PokerCard(++count, card, CardColorEnum.Spade));
                cards.add(new PokerCard(++count, card, CardColorEnum.Heart));
                cards.add(new PokerCard(++count, card, CardColorEnum.Club));
                cards.add(new PokerCard(++count, card, CardColorEnum.Diamond));
            }

        }
    }

    /**
     * 洗牌
     */
    public void ShuffleCards() {
        Collections.copy(GameCards, cards);
        Collections.shuffle(GameCards);
    }


    /**
     * 发牌 并排序
     */
    public void DealCards() {
        for (int i = 0; i < TOTAL_CARDS - HOLE_CARDS; ) {
            PlayerOne.add(GameCards.get(i++));
            PlayerTwo.add(GameCards.get(i++));
            PlayerThree.add(GameCards.get(i++));
        }
        //底牌
        Hole.add(GameCards.get(TOTAL_CARDS - 3));
        Hole.add(GameCards.get(TOTAL_CARDS - 2));
        Hole.add(GameCards.get(TOTAL_CARDS - 1));
        for (List<PokerCard> pokerCards : Arrays.asList(PlayerOne, PlayerTwo, PlayerThree, Hole)) {
            Collections.sort(pokerCards);
        }
    }

    /**
     * 打印扑克牌
     *
     * @param pokerCards
     */
    public void PrintPokerCard(List<PokerCard> pokerCards) {
        StringBuilder s = new StringBuilder();
        for (PokerCard card : pokerCards) {
            //System.out.print(card + " ");
            s.append(card + " ");
        }
        System.out.println(s);
    }


}
